package demo1;
//implements Cloneable标记当前类是可以被克隆的

class Money implements Cloneable{
    public double money=9.9;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
public class Person implements Cloneable{
    public String name;
    public Money money;
    public Person(String name) {
        this.name=name;
        money = new Money();
    }

    @Override
    protected Object clone()
            throws CloneNotSupportedException {
        Person temp = (Person)super.clone();
        temp.money=(Money)this.money.clone();
        return temp;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                '}';
    }
}
